$(document).ready(function(){	
    $("#modifyUser").val(username);
    
	var src = tl_config.his_url;
	var i = src.indexOf('?');

	if(i!=-1){
		var id = src.substring(i+4);	
		
        $.ajax({
        	url:server_url+'/rest/SpecialArticle/selectSpecialArticleById.do?ran='+Math.random()+ '&token=' + token,
        	type:'get',
        	data:{id:id},
        	success:function(data){
        		if(data.retCode=='1003'){
					localStorage.clear();
					window.location.href="login.do";
					return;
				}
        		if(data.retCode==='0000'){         		
        			ue.ready(function(){         			
        				ue.setContent(data.data.content);
        			});
        			$("#id").val(id);
        			$("#description").val(data.data.description);  
        			$("#topic").val(data.data.topic);  
        			$("#title").val(data.data.title);
        			$("#isTop").val(data.data.isTop);  
        			$("[name=filePath]").val(data.data.filePath);
        			$("#imgPath").attr("src",data.data.filePath); 
        			$("#articleType").val(data.data.articleType);
        			$("#writeTime").val(data.data.writeTime);        			
        			$("#position").val(data.data.position);
        			$("#keyWords").val(data.data.keyWords);
        			$("#outherf").val(data.data.outherf);
        			$("#sort").val(data.data.sort);
        			$("#viceTitle").val(data.data.viceTitle);
        			$("#author").val(data.data.author);
        			$("#source").val(data.data.source);
        			$("#pemail").val(data.data.pemail);
        			$("#filePath").val(data.data.filePath);        			   			
        			
                }
        	}
        });
	}	
	
	$("#writeTime").datetimepicker({lang:'ch',
 		timepicker:false,
 		format:'Y-m-d',
 		formatDate:'Y-m-d'
 	});
 	
 	$("input[type=file]").change(function(){ 		
		ajaxfileuploadUtil(this,"article");
	});
	
	//表单验证
	var validate = $("#fromSpecialArticleEdit").validate({		   
			rules:{					
				title:{
					  required:true,
				      remote: { 
		                   url: server_url+'/rest/SpecialArticle/checkTitleEdit.do?timestamp='+Math.random(),
		                   type: "post",
		                   dataType: "json", 
		                   data: {	
		                	         id: function() { return $("#id").val();},
		                	         title: function() { return $("#title").val();},
		                	         token:token
		                         } 
		               },
		               stringMaxLength:30
				},
				articleType:{
					   required:true			  
				   },		  
				   keyWords:{
					   required:true
				   }, 
				   sort:{
					   required:true
				   },
				   author:{
					   required:true
				   },
				   content:{
					   required:true
				   } 
					   
			},
			messages:{				
				title:{
				      required:"不能为空！",
	                  remote:"已存在!",
	                  stringMaxLength:"最多能输入30个字符！"
	                 },
	           articleType:{
	            	 required:"不能为空！"
	             },
	             keyWords:{
	            	required:"不能为空！"            		
	            },
	            sort:{
	            	required:"不能为空！"            		
	            },
	            author:{
	            	required:"不能为空！"            		
	            },
	            content:{
	            	required:"不能为空！"            		
	            }
			},
			submitHandler:function(){
				sub();
			},
			errorPlacement: function(error, element) {
				if ( element.is(":radio") )
					error.appendTo ( element.parent() );
				else if ( element.is(":checkbox") )
					error.appendTo ( element.parent() );
				else if ( element.is("input[name=captcha]") )
					error.appendTo ( element.parent() );
				else
					error.insertAfter(element);
			},
			validClass : 'rightValidate',
		    success: function(label) {
			   label.html("&nbsp;").text(" ") ;
		    }
	 });	

});


//提交
function sub(){	
	if($("#fromSpecialArticleEdit").valid()){
		$.ajax({
			url:server_url+'/rest/SpecialArticle/SpecialArticleEdit.do?ran='+Math.random()+ '&token=' + token,
			type:'post',
			data:$("#fromSpecialArticleEdit").serialize(),
			success:function(data){
				easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose: 2000});
				back();
			}
		});
	}
}


function back(){	
	var url="getSpecialArticleListPage.do?ran="+Math.random();
	tl_config.loadToWorkArea(url);
}

function submitCommit(){
	$("#fromSpecialArticleEdit").submit();
}
